热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

防止隐藏的输入被改变-Preventhiddeninputfrombeingaltered

Thishasbeenstressingmeout..Ihaveahiddeninput:这一直在强调我..我有一个隐藏的输入:<inputtypehidden

This has been stressing me out.. I have a hidden input:

这一直在强调我..我有一个隐藏的输入:


I'm populating the hidden input with valid city names via Javascript prior to submitting the form. Suppose someone wants to submit Banana instead of a city name. The culprit can easily alter the input value via DOM inspectors like Firebug.

在提交表单之前,我通过Javascript使用有效的城市名称填充隐藏的输入。假设有人想提交香蕉而不是城市名称。罪魁祸首可以很容易地通过像Richbug这样的DOM检查员改变输入值。

How can I ensure that the hidden inputs are not tampered with? I'm already validating the input against attacks but as long as I'm accepting alphabetical characters, anything can be submitted, hence banana...

如何确保隐藏的输入不被篡改?我已经验证了针对攻击的输入,但只要我接受字母字符,就可以提交任何内容,因此香蕉......

Edit: I'm referring to hidden inputs in general, not just city names. Any value populated by a script and a value that must be submitted unaltered.

编辑:我指的是隐藏的输入,而不仅仅是城市名称。由脚本填充的任何值和必须不加改变地提交的值。

4 个解决方案

#1


11  

Some ideas:

一些想法:

  1. Server-side only. The easiest way to do this is to use session variables (like $_SESSION) so that all the data kept on the server side, but managing it and keeping separate tabs a user might have open separate can get a little tricky. This option prevents the user from seeing or editing the information.

    仅限服务器端。最简单的方法是使用会话变量(如$ _SESSION),以便保留在服务器端的所有数据,但管理它并保持用户可能单独打开的单独选项卡可能会有点棘手。此选项可防止用户查看或编辑信息。

  2. Make the client carry an encrypted blob. Take all your "temporary but protected" data, combine it somehow (e.g. JSON) and then encrypt* the whole thing with a secret key known only to the server. Base64 the result and put that into the hidden field value. (Note that for a high-security application, you'll also want to work an HMAC into this process, which validates that the ciphertext hasn't been tinkered with.) This option also prevents the user from seeing or editing the information, but makes it easier to handle cases where one user has many tabs open.

    使客户端携带加密的blob。获取所有“临时但受保护”的数据,以某种方式将其组合(例如JSON),然后使用仅为服务器知道的密钥加密*整个事物。 Base64结果并将其放入隐藏字段值。 (请注意,对于高安全性的应用程序,您还需要将HMAC用于此过程,该过程验证密文未被修改。)此选项还会阻止用户查看或编辑信息,但可以更轻松地处理一个用户打开多个选项卡的情况。

  3. Still use not-so-secret hidden input fields, but add an anti-tampering mechanism. So when the page is being generated, take all of your existing "protected" variables, combine them somehow with a server-side secret value, and hash [correction: HMAC] them. Store the hash in its own hidden field. Then after the user submits, you repeat the process and check if the hash matches. If it doesn't, have everything error with security-violation page.

    仍然使用不那么秘密的隐藏输入字段,但添加了防篡改机制。因此,在生成页面时,获取所有现有的“受保护”变量,将它们以某种方式与服务器端秘密值组合,并将它们哈希[更正:HMAC]。将哈希存储在自己的隐藏字段中。然后在用户提交后,重复该过程并检查哈希是否匹配。如果没有,请将安全违规页面的所有内容都包含在内。

*As with all cryptography, doing this the "right" way can be tricky and depends a lot on how you encrypt/verify. There are lot of pitfalls in terms of ciphers and cipher-modes etc.

*与所有加密技术一样,这样做“正确”的方式可能很棘手,并且很大程度上取决于您如何加密/验证。在密码和密码模式等方面存在很多陷阱。

Finally, remember that preventing people from modifying it doesn't mean a user can't copy everything and re-use it later or under another account, unless you take steps to include a "timestamp" etc.

最后,请记住,阻止人们修改它并不意味着用户无法复制所有内容并在以后或其他帐户下重复使用,除非您采取措施包含“时间戳”等。

#2


10  

You can't. You can never, ever rely on user-submitted data. Even if you could prevent the user from modifying the DOM elements (which you can't), you could hardly stop them from submitting an HTTP request with cURL, wget or some other library with whatever fields they chose. Don't trust any data that is sent by the user.

你不能。您永远不能依赖用户提交的数据。即使您可以阻止用户修改DOM元素(您也不能),您很难阻止他们使用cURL,wget或其他一些库提交HTTP请求,无论他们选择哪个字段。不要相信用户发送的任何数据。

If you want to ensure that the value doesn't change, you'll have to store it on the server. PHP has an excellent feature that allows you to do this -- sessions. Store the data in a session, and the user will not be able to modify it, because it will be stored on your server and never transferred to or from the user themselves.

如果要确保值不会更改,则必须将其存储在服务器上。 PHP有一个很好的功能,允许你这样做 - 会话。将数据存储在会话中,用户将无法对其进行修改,因为它将存储在您的服务器上,并且永远不会传输到用户本身或从用户本身传输。

#3


1  

If you are bent upon avoiding the server postback to validate input, you could base64 encode your hidden input and atleast make it harder for people out to tamper with it.

如果您一心想避免使用服务器回发来验证输入,那么您可以对隐藏的输入进行base64编码,至少让人们更难以篡改它。

#4


1  

You can't. A rule to always remember that will save you a lot of thinking and design time. If the browser has it, its not secure.

你不能。永远记住这一规则将为您节省大量的思考和设计时间。如果浏览器有它,它不安全。


推荐阅读
  • 一、选择器性能优化建议1.总是从#id选择器来继承这是jQuery选择器的一条黄金法则。jQuery选择一个元素最快的方法就是用ID来选择了。1$(#content).hide() ... [详细]
  • 本文介绍了南邮ctf-web的writeup,包括签到题和md5 collision。在CTF比赛和渗透测试中,可以通过查看源代码、代码注释、页面隐藏元素、超链接和HTTP响应头部来寻找flag或提示信息。利用PHP弱类型,可以发现md5('QNKCDZO')='0e830400451993494058024219903391'和md5('240610708')='0e462097431906509019562988736854'。 ... [详细]
  • JavaScript与DOM(上)——也适用于新手 – 深入理解JavaScript系列 23
    本文是《JavaScript深度解析》系列文章第23篇(共51篇)文档对象模 ... [详细]
  • 本文介绍了在开发Android新闻App时,搭建本地服务器的步骤。通过使用XAMPP软件,可以一键式搭建起开发环境,包括Apache、MySQL、PHP、PERL。在本地服务器上新建数据库和表,并设置相应的属性。最后,给出了创建new表的SQL语句。这个教程适合初学者参考。 ... [详细]
  • android listview OnItemClickListener失效原因
    最近在做listview时发现OnItemClickListener失效的问题,经过查找发现是因为button的原因。不仅listitem中存在button会影响OnItemClickListener事件的失效,还会导致单击后listview每个item的背景改变,使得item中的所有有关焦点的事件都失效。本文给出了一个范例来说明这种情况,并提供了解决方法。 ... [详细]
  • CF:3D City Model(小思维)问题解析和代码实现
    本文通过解析CF:3D City Model问题,介绍了问题的背景和要求,并给出了相应的代码实现。该问题涉及到在一个矩形的网格上建造城市的情景,每个网格单元可以作为建筑的基础,建筑由多个立方体叠加而成。文章详细讲解了问题的解决思路,并给出了相应的代码实现供读者参考。 ... [详细]
  • 猜字母游戏
    猜字母游戏猜字母游戏——设计数据结构猜字母游戏——设计程序结构猜字母游戏——实现字母生成方法猜字母游戏——实现字母检测方法猜字母游戏——实现主方法1猜字母游戏——设计数据结构1.1 ... [详细]
  • [大整数乘法] java代码实现
    本文介绍了使用java代码实现大整数乘法的过程,同时也涉及到大整数加法和大整数减法的计算方法。通过分治算法来提高计算效率,并对算法的时间复杂度进行了研究。详细代码实现请参考文章链接。 ... [详细]
  • 前景:当UI一个查询条件为多项选择,或录入多个条件的时候,比如查询所有名称里面包含以下动态条件,需要模糊查询里面每一项时比如是这样一个数组条件:newstring[]{兴业银行, ... [详细]
  • 深入理解CSS中的margin属性及其应用场景
    本文主要介绍了CSS中的margin属性及其应用场景,包括垂直外边距合并、padding的使用时机、行内替换元素与费替换元素的区别、margin的基线、盒子的物理大小、显示大小、逻辑大小等知识点。通过深入理解这些概念,读者可以更好地掌握margin的用法和原理。同时,文中提供了一些相关的文档和规范供读者参考。 ... [详细]
  • Ihavethefollowingonhtml我在html上有以下内容<html><head><scriptsrc..3003_Tes ... [详细]
  • 【shell】网络处理:判断IP是否在网段、两个ip是否同网段、IP地址范围、网段包含关系
    本文介绍了使用shell脚本判断IP是否在同一网段、判断IP地址是否在某个范围内、计算IP地址范围、判断网段之间的包含关系的方法和原理。通过对IP和掩码进行与计算,可以判断两个IP是否在同一网段。同时,还提供了一段用于验证IP地址的正则表达式和判断特殊IP地址的方法。 ... [详细]
  • 前端图片合成技术_靠谱的前端需要做哪些准备?
    Web前端开发源于传统的互联网,互联网普及让人才需求量居高不下,随着移动互联网的高速发展,移动终端的前端开发也越来越受到重视, ... [详细]
  • 有个事情移植想不明白
    后端开发|php教程不明白,移植,事情后端开发-php教程为什么我客户端通过http请求服务端服务端发张图片到客户端这个传输为什么那么慢一共也就300多kb但一共传了5秒多如果直接 ... [详细]
  • 高仿CSDN社区树形图 .
    一直感觉CSDN社区的树形结构特别的人性化,直观化。最近做系统的时候需要用到这个树形结构,于是模仿CSDN的树形结构做了一个自己的树形结构, ... [详细]
author-avatar
手机用户2502875927
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有